package com.tms.firtsp.aspect;

import com.tms.firtsp.common.RException;
import com.tms.firtsp.common.Result;
import com.tms.firtsp.common.ResultUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public Result handle(Exception e){

        if(e instanceof RException){
            //是我们自定义的结果异常
            RException rException=(RException)e;
            return ResultUtil.error(rException.getCode(),rException.getMessage());

        }
        return ResultUtil.error(-999,e.getMessage());

    }
}
